let submit_info = document.getElementsByClassName("submit-success");
for(let info of submit_info){
    info.style.display = "none"
}

let teacher_has_logined = document.getElementById("application-scope3").innerHTML
if(teacher_has_logined != "1"){
    //还没有登录，继续跳转到登录页面
   window.location.href = "login-teacher.jsp"
}

$('#release-btn').click(function(){

    for(let info of submit_info){
        info.style.display = "none"
    }


    let today = new Date();
    let year = today.getFullYear();
    let day = today.getDate();
    let month = today.getMonth()+1;
    if(month < 10){
        month = "0" + month
    }
    if(day < 10){
        day = "0" + day
    }
    let day2 = year + "-" + month + "-" + day
    let temperature = 0
    let address = 0
    let contact = 0
    if ($("#inlineCheckbox1").get(0).checked) {
        temperature = 1
    }
    if ($("#inlineCheckbox2").get(0).checked) {
        address = 1
    }
    if ($("#inlineCheckbox3").get(0).checked) {
        contact = 1
    }
    if(temperature == 0 && address == 0 && contact == 0){
        submit_info[2].style.display = "block"
    }else if($("#formGroupExampleInput").val() == "" || $("#formGroupExampleInput2").val()=="" || $("#formGroupExampleInput3").val()== ""){
            submit_info[2].style.display = "block"
    }else{
        if($("#formGroupExampleInput2").val() == day2){
            let signin_has_released = document.getElementById("application-scope4").innerHTML
            console.log(signin_has_released)
            if(signin_has_released == "1"){
                //今天已经发过了
                submit_info[3].style.display = "block"
            }else{
                $.ajax({
                    type: "GET",
                    url: "release",
                    data: {
                        description:$("#formGroupExampleInput").val(),
                        day:$("#formGroupExampleInput2").val(),
                        time:$("#formGroupExampleInput3").val(),
                        temperature:temperature,
                        address:address,
                        contact:contact
                    },
                    dataType: "text",
                    success: function(data){
                        console.log(data)
                        data = JSON.parse(data)
                        if (data.msg == "ok"){
                            document.getElementsByClassName("submit-success")[0].style.display = "block"
                            //setTimeout(function(){window.location.href = "index.jsp"},1500)

                        }else if(data.msg == "error"){
                            document.getElementsByClassName("submit-success")[1].style.display = "block"

                        }
                        console.log("success")

                    }
                });s
            }
        }else{
            $.ajax({
                type: "GET",
                url: "release",
                data: {
                    description:$("#formGroupExampleInput").val(),
                    day:$("#formGroupExampleInput2").val(),
                    time:$("#formGroupExampleInput3").val(),
                    temperature:temperature,
                    address:address,
                    contact:contact
                },
                dataType: "text",
                success: function(data){
                    console.log(data)
                    data = JSON.parse(data)
                    if (data.msg == "ok"){
                        document.getElementsByClassName("submit-success")[0].style.display = "block"
                        //setTimeout(function(){window.location.href = "index.jsp"},1500)

                    }else if(data.msg == "error"){
                        document.getElementsByClassName("submit-success")[1].style.display = "block"

                    }
                    console.log("success")

                }
            });
        }

    }






});
